<template>
<!-- 查看订单详情--有数据渲染 -->
  <div class="member-order-detail" v-if="order">
    <!-- 头部 -->
    <DetailAction :order="order" />
    <!-- 进度 -->
    <DetailStep :order="order" />
    <!-- 物流 -->
    <!-- 因使用async-await 异步需要使用vue3新特性中Suspense组件--内默认两个模板 default+fallback -->
    <Suspense>
      <template #default>
        <DetailLogistics v-if="[3,4,5].includes(order.orderState)" :order="order" />
      </template>
      <!-- 等待的时候显示fallback内容比如loading -->
      <template #fallback>
        <div class="loading">loading...</div>
      </template>
    </Suspense>
    <!-- 信息 -->
    <DetailInfo :order="order" />
  </div>
</template>
<script>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import DetailAction from './components/detail-action'// 订单详情-头部展示
import DetailStep from './components/detail-step'// steps组件--步骤条
import DetailLogistics from './components/detail-logistics'
import DetailInfo from './components/detail-info'
import { findOrderDetail } from '@/api/order'
export default {
  name: 'MemberDetail',
  components: {
    DetailAction,
    DetailStep,
    DetailLogistics,
    DetailInfo
  },
  setup () {
    const route = useRoute()
    const order = ref(null)
    // 获取订单详情
    findOrderDetail(route.params.id).then(data => {
      order.value = data.result
    })
    return { order }
  }
}
</script>
<style scoped lang="less">
.member-order-detail {
  background: #fff;
  height: 100%;
}
.loading {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
}
</style>
